using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace GameLib.GameObjects
{
    public class Piece
    {
        int _id;
        Texture2D _texture;
        Texture2D _shade;
        Vector2 _position;
        Vector2 _originalPosition;
        Vector2 _diffPosition;
        Vector2 _newPosition;
        Point _spriteSize;
        Point _currentSprite;
        Color _color;

        int msSinceLastMove;
        int moveSpeed = 2;

        public Piece(Texture2D texture, Texture2D shade, int id, Point currentSprite, Point spriteSize, Vector2 position)
        {
            this._id = id;
            this._texture = texture;
            this._shade = shade;
            this._position = new Vector2(position.X, position.Y + 300);
            this._originalPosition = position;
            this._diffPosition = (this._position - position) / 100; ;
            this._newPosition = position;
            this._spriteSize = spriteSize;
            this._currentSprite = currentSprite;
            this._color = Color.White;
        }

        public void Update(TimeSpan elaspedGameTime)
        {
            msSinceLastMove += elaspedGameTime.Milliseconds;
            if (msSinceLastMove > moveSpeed)
            {
                msSinceLastMove = 0;
                this._position -= _diffPosition;
                if (this._position == this._newPosition)
                    _diffPosition = Vector2.Zero;
            }



        }

        public void Draw(SpriteBatch spriteBatch)
        {
            //Vector2 ShadowPosition = new Vector2(position.X + 8, position.Y + 8);
            //spriteBatch.Draw(shade, ShadowPosition,
            //    new Rectangle(currentSprite.X * spriteSize.X, currentSprite.Y * spriteSize.Y, 180, 120), Color.DarkSlateBlue); // Sprite piece
            spriteBatch.Draw(_texture, _position,
                new Rectangle(_currentSprite.X * _spriteSize.X, _currentSprite.Y * _spriteSize.Y, _spriteSize.X, _spriteSize.Y), _color); // Sprite piece
        }

        public void ChangePosition(Vector2 newPosition)
        {
            _diffPosition = (this._position - newPosition) / 10;
            this._newPosition = newPosition;
        }



        public Rectangle Bounds
        {
            get { return new Rectangle((int)_newPosition.X, (int)_newPosition.Y, (int)(_spriteSize.X), (int)(_spriteSize.Y)); }
        }

        public int ID
        {
            get { return _id; }
        }

        public Vector2 Position
        {
            get { return _position; }
        }

        public Color Color
        {
            get { return _color; }
            set { _color = value; }
        }

        public int MoveSpeed
        {
            get { return moveSpeed; }
            set { moveSpeed = value; }
        }

        public Vector2 NewPosition
        {
            get { return _newPosition; }
        }

        public Vector2 OriginalPosition
        {
            get { return _originalPosition; }
        }
    }


}
